package com.tocea.formation.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

;

@Entity
@Table(name = "PERSON")
public class Person implements Serializable {

	/**
     * 
     */
	private static Person instance;
	private static Object objetSynchrone__;
	private static final long serialVersionUID = -6273580796367259665L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int _id;

	private String _name;

	private String _forname;

	private String _mail;

	private String _pswrd;

	@OneToMany(mappedBy = "creatorOfThisEvent")
	private Set<Event> _eventsCreated;

	@ManyToMany
	@JoinTable(joinColumns = @JoinColumn(name = "PERSON_ID"), inverseJoinColumns = @JoinColumn(name = "EVENT_ID"))
	private Set<Event> _eventsVisited;

	// /////////////////////////////////////////////////////////////////////////////:

	/**
	 * @param unNom
	 * @param unPrenom
	 * @param unMail
	 * @param unPswrd
	 * @return
	 */
	public static Person getInstance(String unNom, String unPrenom,
			String unMail, String unPswrd) {
		if (null == instance) {
			// synchronized (objetSynchrone__) {
			// if (null == instance) {
			instance = new Person(unNom, unPrenom, unMail, unPswrd);
			// }
			// }
		}
		return instance;
	}
	/**
	 * @param _personne
	 */
	public static Person getInstance(Person _personne) {
		if (null == instance) {
			// synchronized (objetSynchrone__) {
			// if (null == instance) {
			instance = new Person(_personne);
			// }
			// }
		}
		return instance;
	}
	/**
	 * @return
	 */
	public static Person getInstance() {
		return instance;
	}
	private Person() {
	}
	private Person(String __name, String __forname, String __mail, String __psw) {
		super();
		this._name = __name;
		this._forname = __forname;
		this._mail = __mail;
		this._pswrd = __psw;
	}
	/**
	 * @param _personne
	 */
	public Person(Person _personne) {
		this.setID(_personne.getID());
		this.setName(_personne.getName());
		this.setForname(_personne.getForname());
		this.setMail(_personne.getMail());
	}
	public Integer getID() {
		return this._id;
	}
	private void setID(Integer _iD) {
		this._id = _iD;
	}
	/**
	 * @return
	 */
	public String getName() {
		return this._name;
	}
	private void setName(String _name) {
		this._name = _name;
	}
	public String getForname() {
		return this._forname;
	}
	private void setForname(String _forname) {
		this._forname = _forname;
	}
	public String getMail() {
		return this._mail;
	}
	private void setMail(String _mail) {
		this._mail = _mail;
	}
	private String getPsw() {
		return this._pswrd;
	}
	private void setPsw(String _psw) {
		this._pswrd = _psw;
	}
	public static void disconnect() {
		instance = null;

	}
}